import { playMode } from 'common/js/config'

const state = {
  playing: false,
  fullScreen: false,
  playlist: [],
  sequenceList: [],
  mode: playMode.sequence,
  currentIndex: -1
}

const actions = {
  selectPlay({ commit, state }, { list, idx }) {
    commit('setPlayList', list)
    commit('setCurrentIndex', idx)
    commit('setFullScreen', true)
    commit('setPlayingState', true)
  }
}

const mutations = {
  setPlayingState(state, res) {
    state.playing = res
  },
  setFullScreen(state, res) {
    state.fullScreen = res
  },
  setPlayList(state, res) {
    state.playlist = res
  },
  setSequenceList(state, res) {
    state.sequenceList = res
  },
  setMode(state, res) {
    state.mode = res
  },
  setCurrentIndex(state, res) {
    state.currentIndex = res
  }
}

const getters = {
  playing(state) {
    return state.playing
  },
  fullScreen(state) {
    return state.fullScreen
  },
  playlist(state) {
    return state.playlist
  },
  sequenceList(state) {
    return state.sequenceList
  },
  mode(state) {
    return state.mode
  },
  currentIndex(state) {
    return state.currentIndex
  },
  currentSong(state) {
    return state.playlist[state.currentIndex] || {}
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters
}
